package com.sunfeng.chap4.begintransfile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description:
 * @author: 孙 峰
 * @time: 2020/11/9 15:44
 */
public class Server {
    public static void main(String[] args) {

        try {
            byte[] bytes = new byte[2048];
            ServerSocket serverSocket = new ServerSocket(8088);
            Socket socket = serverSocket.accept();
            InputStream inputStream = socket.getInputStream();
            int readLength = inputStream.read(bytes);
            FileOutputStream fileOutputStream = new FileOutputStream(new File("d:\\a.png"));
            while (readLength != -1) {
                fileOutputStream.write(bytes, 0, readLength);
                readLength = inputStream.read(bytes);
            }
            fileOutputStream.close();
            inputStream.close();
            socket.close();
            serverSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
